package com.pureut.quality.controller;


import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.quality.domain.dto.AuditNonconformityDto;
import com.pureut.quality.domain.dto.ExternalAuditPlanDto;
import com.pureut.quality.domain.vo.AuditNonconformityVo;
import com.pureut.quality.domain.vo.ExternalAuditPlanVo;
import com.pureut.quality.domain.vo.SubmitVo;
import com.pureut.quality.service.AuditNonconformityService;
import com.pureut.quality.service.ExternalAuditPlanService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassDescription: 外审不符合项报告
 * @Author: YSL
 * @Created: 2025/4/8 10:19
 */
@RestController
@RequestMapping("/auditNonconformity")
public class AuditNonconformityController extends BaseController {

    /**
     * 外审不符合项报告实现层
     */
    @Resource
    AuditNonconformityService auditNonconformityService;

    /**
     * 外审不符合项报告列表
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:list")
    @GetMapping("/list")
    public TableDataInfo list(AuditNonconformityVo auditNonconformityVo)
    {
        startPage();
        List<AuditNonconformityDto> list = auditNonconformityService.listAuditNonconformity(auditNonconformityVo);
        return getDataTable(list);
    }

    /**
     * 根据id获取详细信息
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id)
    {
        return AjaxResult.success(auditNonconformityService.getInfo(id));
    }

    /**
     * 外审不符合项报告新增
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AuditNonconformityVo auditNonconformityVo) throws Exception {
        return toAjax(auditNonconformityService.insertAuditNonconformity(auditNonconformityVo));
    }

    /**
     * 外审不符合项报告修改
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告修改", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AuditNonconformityVo auditNonconformityVo) throws Exception {
        return toAjax(auditNonconformityService.updateAuditNonconformity(auditNonconformityVo));
    }

    /**
     * 外审不符合项报告删除
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:remove")
    @Log(title = "外审不符合项报告删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") String ids){
        return toAjax(auditNonconformityService.removeAuditNonconformity(ids));
    }

    /**
     * 外审不符合项报告提交
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告修改", businessType = BusinessType.INSERT)
    @PutMapping("/submit/{id}")
    public AjaxResult submit(@PathVariable("id") Long id)  {
        return toAjax(auditNonconformityService.submitAuditNonconformity(id));
    }

    /**
     * 外审不符合项报告审核
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告审核", businessType = BusinessType.INSERT)
    @PutMapping("/examine")
    public AjaxResult examine(@Validated @RequestBody SubmitVo submitVo){
        return toAjax(auditNonconformityService.examineAuditNonconformity(submitVo));
    }

    /**
     * 外审不符合项报告撤销
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告修改", businessType = BusinessType.INSERT)
    @PutMapping("/revoke/{id}")
    public AjaxResult revoke(@PathVariable("id") Long id) {
        return toAjax(auditNonconformityService.revokeAuditNonconformity(id));
    }

    /**
     * 外审不符合项报告关节
     */
//    @RequiresPermissions("quality:verifyconfig:badcategory:add")
    @Log(title = "外审不符合项报告关结", businessType = BusinessType.INSERT)
    @PutMapping("/close")
    public AjaxResult revoke(@Validated @RequestBody SubmitVo submitVo) {
        return toAjax(auditNonconformityService.closeAuditNonconformity(submitVo));
    }
}
